/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package other;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Recipe;
import model.SearchList;

/**
 *
 * @author zimi
 */
public class RecipeTableModel extends AbstractTableModel {

    SearchList model = new SearchList();//new ArrayList<Recipe>();

    public RecipeTableModel(SearchList recipes) {
        useRecipes(recipes);
    }

    public final void useRecipes(SearchList recipes) {
        model.clear();
       
        for(int i=0;i<recipes.size();i++){
            Recipe recipe = (Recipe)recipes.elementAt(i);
            addRecipe(recipe);
        }
    }

    public final void addRecipe(Recipe recipe) {
        model.add(recipe);
    }

    public int getRowCount() {
        return model.size();

    }

    public int getColumnCount() {
        return 2;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Object value = null;
        switch(columnIndex) {
            case 0:
                value = model.get(rowIndex);
                break;
            case 1:
                Recipe recipe = (Recipe) model.get(rowIndex);
                value = recipe.getCategory();
                break;
            case 2:
                value = "Usuń";
                break;
        }
        return value;
    }

    @Override
    public String getColumnName(int column) {
        String name = null;
        switch(column) {
            case 0:
                name = "Nazwa potrawy";
                break;
            case 1:
                name = "Kategoria";
        }
        return name;
    }



}
